package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.AdminAddDto;
import com.huirui.server.pojo.dto.AdminLoginDto;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.AdminInfoVo;
import com.huirui.server.service.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/admin")
@Slf4j
@Validated
@Tag(name = "员工管理", description = "服务器员工管理")
public class AdminController {

    @Resource
    private AdminService adminService;

    @PostMapping("/login")
    @Operation(summary = "员工登录")
    public Result<String> login(@RequestBody @Validated AdminLoginDto adminLoginDto, HttpServletRequest request) {
        String token = adminService.login(adminLoginDto, request);
        return Result.success(token);
    }

    @PostMapping("/add")
    @Operation(summary = "新增员工")
    public Result<Void> addEmployee(@RequestBody @Validated AdminAddDto adminAddDto) {
        adminService.addEmployee(adminAddDto);
        return Result.success();
    }

    @GetMapping("/info")
    @Operation(summary = "获取用户信息")
    public Result<AdminInfoVo> getAdminInfo() {
        AdminInfoVo adminInfoVo = adminService.getAdminInfo();
        return Result.success(adminInfoVo);
    }
}
